package com.flyfish.ddns.send;

import java.io.IOException;
import java.util.List;

import com.aliyuncs.alidns.model.v20150109.DescribeDomainsRequest;
import com.aliyuncs.alidns.model.v20150109.DescribeDomainsResponse;
import com.aliyuncs.alidns.model.v20150109.DescribeDomainsResponse.Domain;
import com.flyfish.ddns.utils.DdnsUtils;
import com.flyfish.ddns.utils.PropertiesUtil;
import com.flyfish.ddns.utils.WriteLog;
import com.flyfish.ddns.vo.AliyunVo;

/**
 * 阿里sdk
 * 
 * @author tanchong
 *
 */
public class DemoListDomains {

	/**
	 * 设置参数
	 * 
	 * @param request
	 */
	public void setParam(DescribeDomainsRequest request, AliyunVo yunVo) {
		// 设置参数
		request.putQueryParameter("RecordId", yunVo.getRecordId());
		request.putQueryParameter("RR", yunVo.getRr());
		request.putQueryParameter("Type", yunVo.getType());
		request.putQueryParameter("Value", yunVo.getIpV4());
		request.putQueryParameter("TTL", yunVo.getTTL());
	}

	/**
	 * 解析DNS信息
	 */
	public void analysisDns(AliyunVo yunVo) {
		// 获取公网ip
		String actionName = "UpdateDomainRecord";
		DescribeDomainsRequest request = DdnsUtils.getRequest(actionName);
		DescribeDomainsResponse response;
		setParam(request, yunVo);
		// 调用阿里服务
		try {
			response = DdnsUtils.getClient().getAcsResponse(request);
			List<Domain> list = response.getDomains();
			for (Domain domain : list) {
				System.out.println(domain.getDomainName());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		try {
			System.out.println("开始ddns检查");
			WriteLog.writeLogInfo("开始ddns检查");
			UpdateDomainRecord demo = new UpdateDomainRecord();
			demo.analysisDns();
			System.out.println("ddns运行结束");
			WriteLog.writeLogInfo("ddns运行结束");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}